package com.wy2.eclipse.tool.lib.git;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class GitElementList extends ArrayList<GitElement> {

    /**
     * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
     */
    private static final long serialVersionUID = 1L;
    
    
    public void add(GitElementStatus status,Set<String> sets) {
        if(sets==null || sets.size()<1) {
            return;
        }
        for (String relativePath : sets) {
            add(new GitElement(status, relativePath));
        } 
    }

    
    public String[] getPaths() {
        return getPaths(null);
    }
    public String[] getPaths(GitElementStatus status) {
        List<String> paths=new ArrayList<>();
        Iterator<GitElement> iterator = this.iterator();
        GitElement gitElement=null;
        while(iterator.hasNext()) {
            gitElement=iterator.next();
            if(status==null || gitElement.getStatus()==status.getStatus()) {
                paths.add(gitElement.getRelativePath());
            }            
        }        
        return paths.toArray(new String[0]);
    }
    public String getPrettyString() {
        return getPrettyString(null);
    }
    public String getPrettyString(GitElementStatus status) {
        StringBuilder listSb=new StringBuilder();
        Iterator<GitElement> iterator = this.iterator();
        GitElement gitElement=null;
        while(iterator.hasNext()) {
            gitElement=iterator.next();
            if(status==null || gitElement.getStatus()==status.getStatus()) {
                listSb.append(GitElementStatus.Parse(gitElement.getStatus()).getStatusName());
                listSb.append(" | ");
                listSb.append(gitElement.getRelativePath());                
                listSb.append("\n");
            }            
        }        
        return listSb.toString();
    }

    
    
}
